;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Report.PayBackSummary", [])
        .controller("PayBackSummaryCtrl", ["$scope", "$state", "ybWidget", "ybHttp", "MESG_TYPE", "$filter", "$timeout", "UserContextService", "$stateParams", function ($scope, $state, ybWidget, ybHttp, MESG_TYPE, $filter, $timeout, UserContextService, $stateParams) {
            var btnPermissionCode = {
                saleOrderExport: window.ActionCode.saleOrderExport,
            };

            $scope.btnPermission = {
                saleOrderExport: true,
            };

            function setBtnPermission() {
                for (var key in btnPermissionCode) {
                    $scope.btnPermission[key] = UserContextService.CheckPermission([btnPermissionCode[key]]);
                }
            }

            $scope.markInfo = {
                curRow: -1
            };

            $scope.pageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };

            $scope.exportParam = {
                allUrl: ybHttp.RequestUrl("device", "/backMoney/export")
            };

            $scope.toolbarConfig = {
                showAdvanceSearch: false,
                showColConfig: false,
            };
            $scope.switchToolbar = function (toolbar) {
                if (!!$scope.toolbarConfig["show" + toolbar]) {
                    $scope.toolbarConfig["show" + toolbar] = false;
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig["show" + toolbar] = true;
                    });
                }
            };

            $scope.condition = {};
            $scope.dataList = [];

            $scope.tbConf = {
                scrollWidth: 2250,
                tableCol: [
                    {
                        name: "回款月份",
                        dataField: "backMonthStr",
                        width: 100,
                        isShow: true
                    },
                    {
                        name: "上中下旬",
                        dataField: "durationStr",
                        width: 100,
                        isShow: true
                    },
                    {
                        name: "回款日期",
                        dataField: "backTimeShow",
                        width: 140,
                        isShow: true
                    },
                    {
                        name: "客户名称",
                        dataField: "customName",
                        width: 170,
                        isShow: true
                    },
                    {
                        name: "NC客户编码",
                        dataField: "customNcCode",
                        width: 170,
                        isShow: true
                    },
                    {
                        name: "PMS客户编码",
                        dataField: "customPmsCode",
                        width: 170,
                        isShow: true
                    },
                    {
                        name: "客户类型",
                        dataField: "customType",
                        width: 170,
                        isShow: true
                    },
                    {
                        name: "回款金额（元）",
                        dataField: "backMoney",
                        width: 170,
                        isShow: true
                    },
                    {
                        name: "回款方式",
                        dataField: "backType",
                        width: 170,
                        isShow: true
                    },
                    {
                        name: "打款名称",
                        dataField: "payer",
                        width: 170,
                        isShow: true
                    },
                    {
                        name: "打款时间",
                        dataField: "payTimeStr",
                        width: 140,
                        isShow: true
                    },
                    {
                        name: "承兑票号",
                        dataField: "billNo",
                        width: 170,
                        isShow: true
                    },
                    {
                        name: "回款期限",
                        dataField: "backDurationStr",
                        width: 170,
                        isShow: true
                    },
                    {
                        name: "是否开票",
                        dataField: "billStateShow",
                        width: 100,
                        isShow: true
                    },
                    {
                        name: "开票时间",
                        dataField: "billTimeShow",
                        width: 140,
                        isShow: true
                    },
                ]
            };

            $scope.reset = function () {
                $scope.condition = {};
            };

            $scope.search = function (curpage) {
                getDataList(curpage);
            };

            $scope.selectRow = function (index) {
                $scope.markInfo.curRow = index;
            };

            $scope.checkDate = function (obj, startFiled, endFiled) {
                var timeFormatObj = ybWidget.CheckDate(obj[startFiled], obj[endFiled]);
                if (!!timeFormatObj.tStart) {
                    obj[startFiled] = timeFormatObj.tStart;
                }
                if (!!timeFormatObj.tEnd) {
                    obj[endFiled] = timeFormatObj.tEnd;
                }
            };

            function getDataList(curPage) {
                $scope.markInfo.curRow = -1;
                if (!!curPage) {
                    $scope.pageInfo.curPage = curPage;
                }

                var service = "device";
                var reqUrl = "/backMoney/pageList";
                var param = {
                    pageNum: $scope.pageInfo.curPage,
                    pageSize: $scope.pageInfo.pageSize,
                    filters: angular.copy($scope.condition)
                };
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    angular.forEach(resp.value.list, function (item) {
                        item.backTimeShow = $filter("YbDate")(item.backTime, 'yyyy-MM-dd HH:mm:ss');
                        item.billStateShow = $filter("TrueOrFalse")(item.billState, 'normal');
                        item.billTimeShow = $filter("YbDate")(item.billTime, 'yyyy-MM-dd HH:mm:ss');
                    });
                    $scope.pageInfo.totalRows = resp.value.total;
                    $scope.pageInfo.totalPages = resp.value.pages;
                    $scope.dataList = resp.value.list;
                });
            }

            (function () {
                UserContextService.SetBtnPermission(setBtnPermission);
                getDataList();
            })();
        }])
    ;
})(window, window.angular);